﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DataModel;

namespace TestModel
{
    /// <summary>
    /// Summary description for InitializeData
    /// </summary>
    [TestClass]
    public class InitializeData
    {
        private SocialPhotoModelContainer model;
        public InitializeData()
        {
            model = new SocialPhotoModelContainer();
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]        
        public void InitCategories()
        {
            int preCategoryCount = model.Categories.Count();
            model.AddToCategories(new Category { Name = "Animal" });
            model.AddToCategories(new Category { Name = "Landscape" });
            model.AddToCategories(new Category { Name = "Fun" });
            model.AddToCategories(new Category { Name = "Erotica" });
            model.AddToCategories(new Category { Name = "Black & White" });
            model.AddToCategories(new Category { Name = "Objects" });
            model.AddToCategories(new Category { Name = "Art & Effect" });
            model.AddToCategories(new Category { Name = "Portrait" });
            model.SaveChanges();
            
            Assert.AreEqual(8,  model.Categories.Count() - preCategoryCount);
        }

        [TestMethod]
        public void InitUsers()
        {
            int preTagCount = model.Users.Count();
            model.AddToUsers(new User { Name= "CuongTrinh", Password= "123456" });
            model.AddToUsers(new User { Name = "Ha", Password = "123456" });
            model.AddToUsers(new User { Name = "Trung", Password = "123456" });
            model.SaveChanges();
            Assert.AreEqual(3, model.Users.Count() - preTagCount);
        }

        [TestMethod]
        public void InitPhotos()
        {
            try
            {
                //Category cat1 = model.Categories.First();//.Select(0);
                User user1 = model.Users.First();//.Select(0);
                //int preTagCount = model.Photos.Count();
                //model.AddToPhotos(new Photo { FileName = "image1.jpg", Likes = 1, Dislikes = 1, ContentType = "image",
                //                                User = user1, Category = cat1});
                //model.SaveChanges();
                //Assert.AreEqual(1, model.Photos.Count() - preTagCount);
            }
            catch (Exception ex)
            {
            }
        }
    }
}
